﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Model
{
    /// <summary>
    /// 优酷电影条目
    /// </summary>
    public class YouKuFilmItem
    {
        /// <summary>
        /// 电影名称
        /// </summary>
        public string VideoName { get; set; }

        /// <summary>
        /// id
        /// </summary>
        public string VideoId { get; set; }

        /// <summary>
        /// 优酷播放地址
        /// </summary>
        public string VideoURL { get; set; }

        /// <summary>
        /// 影片缩略图地址
        /// </summary>
        public string VideoImgURL { get; set; }

        public override string ToString()
        {
            return VideoName + "\t" + VideoId + "\t" + VideoURL + "\t" + VideoImgURL;
        }

        public override bool Equals(object obj)
        {
            if (obj == null)
                return false;
            if (obj.GetType() != typeof(YouKuFilmItem))
                return false;
            YouKuFilmItem c = obj as YouKuFilmItem;
            return this.VideoId.Equals(c.VideoId);
        }

        public override int GetHashCode()
        {
            if (string.IsNullOrEmpty(VideoId))
            {
                return -1;
            }
            return VideoId.GetHashCode();
        }

        public void DownLoadImage()
        {
            //下载图片
            if (string.IsNullOrEmpty(VideoImgURL) == false)
            {
                using (MyWebClient _client = new MyWebClient())
                {
                    try
                    {
                        string filename = @"image\yk_" + DateTime.Now.ToString("yyyyMMddhhmmssffff") + ".jpg";
                        _client.DownloadFile(VideoImgURL, filename);

                        VideoImgURL = filename;
                    }
                    catch (Exception) { }
                }
            }
        }
    }
}
